<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="http://soft.huruqing.cn/code/common.css">
    <style>
        .box>* {
            border: 1px solid;
            flex-grow: 1;
            width: 50%;
        }
    </style>
</head>

<body>
    <h1 style="text-align: center;">js数组转json数组</h1>

    <div class="flex jc-sb box">
        <textarea style="padding:20px;" onchange="handleBlur()" cols="100" rows="30" placeholder="请输入js对象或数组"></textarea>
        <textarea style="padding:20px;" class="ml-10 content" cols="100" rows="30"  placeholder="结果展示在这里"></textarea>
    </div>
    <script>
        function handleBlur() {
            let el = document.querySelector('textarea');
            let value = el.value; 
            let obj = eval(value); 
            document.querySelector('.content').value = JSON.stringify(obj);
        }
    </script>
</body>

</html>